<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>通过百度地图API获取当前位置</title>
    <script src="js/zepto.min.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=GlUjAmOMusVFKHklb9yTgllA2PIcGniT"></script>
    <script type="text/javascript">
        function getCurrPosition() {
            //这里提示用到了zepto.min.js
            var loading = $.loading({
                content: '正在获取位置...'
            });
            var geolocation = new BMap.Geolocation();
            geolocation.getCurrentPosition(function(r) {
                loading.hide();
                if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                    var geoc = new BMap.Geocoder();
                    var pt = r.point;
                    geoc.getLocation(pt, function(rs) {
                        var addComp = rs.addressComponents;
                        //addComp.province 省份
                        $("#sfdd").val(addComp.city + addComp.district + addComp.street + addComp.streetNumber);
                    });
                } else {
                    var msg = '获取位置失败!';
                    switch (this.getStatus()) {
                        case BMAP_STATUS_UNKNOWN_LOCATION:
                            msg += "位置结果未知。";
                            break;
                        case BMAP_STATUS_SERVICE_UNAVAILABLE:
                            msg += "定位服务不可用。";
                            break;
                        case BMAP_STATUS_TIMEOUT:
                            msg += "定位超时";
                            break;
                    }
                    var tip = $.tips({
                        content: msg,
                        stayTime: 1000,
                        type: "success"
                    });
                }
            }, {
                enableHighAccuracy: true
            });
        }
    </script>
</head>
<body>
<div class="ui-form-item ui-border-b">
    <label> 事发地点： </label>
    <input placeholder="请输入事发地点" id="sfdd" name="sfdd" type="text" style="padding-right: 25px;">
    <a href="javascript:getCurrPosition();" class="ui-icon-pin pull-right"></a>
</div>

</body>
</html>